package com.example.yang_app_sixth_server2;

import android.os.Handler;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

class ServerListener implements Runnable{
    public static ArrayList<Socket> socketList=null;
    Handler handler;
    public ServerListener(Handler handler){
        this.handler=handler;
        socketList=new ArrayList<>();
    }

    @Override
    public void run() {
        try {
            ServerSocket ss=new ServerSocket(30000);
            while(true){
                Socket sk=ss.accept();//在这边阻塞，直到接收到客户端的TCP请求；如果没有接收到新请求不会往下运行
                socketList.add(sk);
                new Thread(new ServerProcessThread(sk,handler)).start();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
